#!/usr/bin/env python

# (c) 2007-2011 Helsinki University of Technology and University of Helsinki
# Licensed under the MIT license; see LICENSE.txt for more information.

from rdf import *
from rdfcache import loadrdf
import sys



class ModelService:
  def __init__(self, config, verbose=False):
    self._config = config
    self._verbose = verbose
    self._models = {}
  
  def getModel(self, name):
    if self._models.has_key(name):
      return self._models[name]
    
    for n, fn in self._config.getModelSources():
      if n == name:
        model = loadrdf(fn, dbg=self._verbose, formats=RDF_FORMATS)
#        model = loadrdf(fn, backend='sleepycat', dbg=self._verbose, formats=RDF_FORMATS)
        self._models[name] = model
        return model
    
    print >>sys.stderr, "Warning: no model with name %s defined" % name
    return None

  def forgetModel(self, name):
    if self._models.has_key(name):
      del self._models[name]